package webkf;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class Spgl {
    private Connection conn;

    public boolean addSP(SP sp)throws Exception,ClassNotFoundException{
        Connection conn=Ljsq.getConnection();
        Statement stmt=conn.createStatement();
        String sqlString="insert into ol value('"+sp.getId()+"','"+sp.getName()+"','"+sp.getJg()+"')";
        return stmt.executeUpdate(sqlString) >0;
    }


    public boolean delSP(SP sp)throws Exception,ClassNotFoundException{
        Connection conn=Ljsq.getConnection();
        Statement stmt=conn.createStatement();
        String sqlString="delect from ol where id='"+sp.getId()+"'";
        return stmt.executeUpdate(sqlString) >0;
    }

    public boolean updateSP(SP sp)throws Exception,ClassNotFoundException{
        Connection conn=Ljsq.getConnection();
        Statement stmt=conn.createStatement();
        String sqlString="update ol set id='"+sp.getId()+"',name='"+sp.getName()+"',jg='"+sp.getJg()+"'";
        return stmt.executeUpdate(sqlString)>0;
    }

    public ArrayList<SP> listAllSP()throws Exception,ClassNotFoundException{
        Connection conn=Ljsq.getConnection();
        Statement stmt=conn.createStatement();
        ResultSet rs=stmt.executeQuery("select * from ol");

        ArrayList<SP> arr=new ArrayList<SP>();
        while (rs.next()){
        SP sp=new SP();
        sp.setId(rs.getString("id"));
        sp.setName(rs.getString("name"));
        sp.setJg(rs.getFloat("jg"));
        arr.add(sp);
        }
        return arr;
    }


}
